<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="/WEB-INF/tlds/helpers.tld" prefix="helpers"%>
<%@ taglib uri='/WEB-INF/tlds/security.tld' prefix='sec'%>

<div class="main-post">

    <c:if test="${not empty view.post}">
        <div class="post-entry">
            <h2><c:out value="${view.post.title}" /></h2>
            <div class="post-info"><b>
                    <c:out value="${view.post.author.name}" />
                    <fmt:formatDate pattern="yyyy-MM-dd" value="${view.post.date}" />
                </b>
            </div>
            <div class="post-content">
                <helpers:FormatWiki>
                    <c:out value="${view.post.content}" escapeXml="false" />
                </helpers:FormatWiki>
            </div>
            <div>
                Tags: <c:out value="${view.post.tagString}" />
            </div>
            <sec:isAdmin>
                <ul class="post-actions">
                    <li>
                        <a href="${request.contextPath}/blog/edit/${view.post.id}">Edit</a>
                    </li>
                    <li>
                        <a href="${request.contextPath}/blog/delete/${view.post.id}">Delete</a>
                    </li>
                </ul>
            </sec:isAdmin>
        </div>

        <div class="add-comment">
            <form method="post" 
                  action="${request.contextPath}/blog/comment/add/${view.post.id}">
                <div>
                    <textarea id="content"
                              class="comment-content-edit"
                              name="content" 
                              title="comment"></textarea>
                </div>
                <input type="submit" value="Comment" />
            </form>
        </div>

        <div class="blog-comments">
            <c:forEach var="comment" items="${view.post.comments}">
                <div class="blog-comment">
                    <div class="comment-user"><c:out value="${comment.user.name}" /></div>
                    <div class="comment-date"><c:out value="${comment.date}" /></div>
                    <div class="comment-content"><c:out value="${comment.content}" /></div>
                    <ul class="comment-actions">
                        <c:if test="${user == comment.user}">
                            <li><a href="${request.contextPath}/blog/editComment/${comment.id}">Edit</a></li>
                        </c:if>
                        <sec:isAdmin>
                            <li>
                                <a href="${request.contextPath}/blog/deleteComment/${comment.id}">Delete</a>
                            </li>
                        </sec:isAdmin>
                    </ul>
                </div>
            </c:forEach>
        </div>
    </c:if>
</div>